namespace Study303 {

  interface IArrType {
    length: number
  }

  function getLegnth<T extends IArrType>(arg: T): number {
    return arg.length //报错 T上不存在属性“length”
  }

  // 泛型在没有去调用传类型的情况，会被认定为是any


  type obj1Type = {
    a: string;
    b: string;
    c: string;
    d: string;
  }

  const obj1 = {
    a: 'a1',
    b: 'b1',
    c: 'c1',
    d: 'c1'
  }


  type obj2Type = {
    e: string;
    f: string;
    g: string;
    h: string;
  }

  const obj2 = {
    e: 'eee',
    f: 'fff',
    g: 'ggg',
    h: 'hhhh'
  }


  // <T,K  extends keyof T>
  // <obj1Type,K  extends (keyof obj1Type)= a,b,c,d>
  // <obj2Type,K  extends (keyof obj2Type)= e,f,g,h>


  function getObjItem<T, K extends keyof T>(obj: T, key: K) {
    return obj[key]
  }

  console.log(getObjItem(obj1, 'a'));
  console.log(getObjItem(obj1, 'b'));
  console.log(getObjItem(obj1, 'c'));
  console.log(getObjItem(obj1, 'd'));


  console.log(getObjItem(obj2, 'e'));
  console.log(getObjItem(obj2, 'f'));
  console.log(getObjItem(obj2, 'g'));
  console.log(getObjItem(obj2, 'g'));




}

export {}